import 'package:flutter/material.dart';
import 'package:gesture_exp/cut_canvas/cut_canvas.dart';

main(List<String> args) {
  runApp(MaterialApp(
    home: CanvasTestPage(),
  ));
}

class CanvasTestPage extends StatefulWidget {
  CanvasTestPage({Key key}) : super(key: key);

  @override
  _CanvasTestPageState createState() => _CanvasTestPageState();
}

class _CanvasTestPageState extends State<CanvasTestPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          _buildContent(),
        ],
      ),
    );
  }

  CutCanvasController canvasController;

  final int decodeImageWidth = 4797;
  final int decodeImageHeight = 3198;

  @override
  void initState() {
    super.initState();
    canvasController = CutCanvasController(
      photoAspectRatio: decodeImageWidth / decodeImageHeight,
      initialAspectRatio: decodeImageWidth / decodeImageHeight,
    );
  }

  Widget _buildContent() {
    Widget widget = CutCanvasWidget(
      maxScale: AdaptiveScale.contained * 15.0,
      minScale: AdaptiveScale.contained * 1.0,
      initialScale: AdaptiveScale.covered * 1.0,
      controller: canvasController,
      child: Image.asset('images/f.jpg'),
    );

    widget = Container(
      margin: EdgeInsets.all(20),
      decoration: BoxDecoration(
        border: Border.all(
          color: Colors.red,
          width: 1,
        ),
      ),
      child: widget,
    );

    widget = Positioned.fill(
      child: widget,
    );

    return widget;
  }
}
